function unparse_form($form, $form_data, $controller) {
	let $tpl_data = $form.data;
	let $tpl = $form.parse;

	$tpl_data.forEach(($value, $key) => {
	
		let $temp_html = '';
		$value['value'] = $form_data[$value['name']]? $form_data[$value['name']] : $value['value'];//通用

		switch($value['leipiplugins']) {
			case 'text':
				$temp_html = '<input type="text" value="'+$value['value']+'"  name="'+$value['name']+'"  style="'+$value['style']+'"/>';
				break;
            case 'textarea':
                    $temp_html = '<textarea  name="'+$value['name']+'" id="'+$value['name']+'" value="'+$value['value']+'" style="'+$value['style']+'">';
                    $temp_html += $value['value'];
                    $temp_html += '</textarea>';
                    if($value['orgrich'])
                    {
                        $temp_html += '<script>'+
                            'UE.getEditor("'+$value['name']+'",{'
                                + 'toolbars:[['
                                + '"fullscreen", "source", "|","bold", "italic", "underline","|", "justifyleft", "justifycenter", "justifyright", "justifyjustify"]],wordCount:false,elementPathEnabled:false'
                            +' });</script>';
                    }
                break;
            case 'radios':
                $temp_html =  '';
                $value['options'].forEach($item => 
                {
                    $checked = '';
                    if($form_data[$value['name']])//原 默认值
                    {
                       $checked =  $form_data[$value['name']] == $item['value'] ? 'checked="checked"' : '';
                    }else if($item['checked'])//判断isset 就可以,在ie中，checked的值是空的
                    {
                        $checked = 'checked="checked"';
                    }
                    $temp_html +='<input type="radio" name="'+$value['name']+'" value="'+$item['value']+'" '+$checked+'>'+$item['value']+'&nbsp;';
                })
                break;
            case 'checkboxs':
                $temp_html = '';

                $value['options'].forEach($item =>
                {
                    $checked = '';
                    if($form_data[$item['name']])//原 默认值
                    {
                       $checked =  $form_data[$item['name']] >0 ? 'checked="checked"' : '';
                    }else if($item['checked'])//判断isset 就可以,在ie中，checked的值是空的
                    {
                        $checked = 'checked="checked"';
                    }
                    $temp_html += '<input type="checkbox" name="'+$item['name']+'" value="'+$item['value']+'" '+$checked+'>'+$item['value']+'&nbsp;';
                   
                })
                $value['name'] = $value['parse_name'];
                break;
            case 'select':
                //设置过默认值  清空它  
                if($form_data[$value['name']])
                {
                    if($value['selected'])
                    {
                        $value['content'] = str_replace('selected="selected"','',$value['content']);
                    }
                    $selected = '';
                    if($form_data[$value['name']]==$value['value'])
                        $selected = 'selected="selected"';
                    //重新定义默认值 
                    $value['content'] = str_replace('value="'+$value['value']+'"','value="'+$value['value']+'" '+$selected,$value['content']);
                }
                $temp_html = $value['content']; 
                break;

            /*case 'macros':
                $temp_html = macros_parse($value,$form_data[$value['name']],$controller);
                break;*/
            case 'progressbar':
                if($controller['action']=='edit')
                {
                    $value['value'] = parseFloat($value['value']);
                    $value['value'] = $value['value']>0 ? $value['value'] : parseFloat($value['orgvalue']);
                    $temp_html ='进度 <input type="text" style="width:40px" name="'+$value['name']+'" value="'+$value['value']+'"/> %'; 
                }else if($controller['action']=='view')
                {
                    $temp_html = '<div class="progress progress-striped"><div class="bar '+$value['orgsigntype']+'" style="width: '+$value['value']+'%;"></div></div>';
                }else if($controller['action']=='preview')
                {
                    $temp_html = '<div class="progress progress-striped"><div class="bar '+$value['orgsigntype']+'" style="width: '+$value['orgvalue']+'%;"></div></div>';
                }
               
                break;
            case 'qrcode'://未处理生成二维码
           
                let $orgtype = '';
                let $qrcode_value = null;
                if($value['orgtype']=='text')
                {
                    $orgtype = '文本';
                }else if($value['orgtype']=='url')
                {
                    $orgtype = '超链接';
                }else if($value['orgtype']=='tel')
                {
                    $orgtype = '电话';
                }
                if($value['value'])
                    $qrcode_value = $value['value'];
                if($controller['action']=='edit')
                {
                    $temp_html = $orgtype+'二维码 <input type="text" name="'+$value['name']+'" value="'+$value['src']+'"/>'; 
                }else if($controller['action']=='view')
                {
                    //可以采用  http://qrcode.leipi.org/ 

                    $style = '';
                    if($value['orgwidth']>0)
                    {
                        $style += 'width:'+$value['orgwidth']+'px;';
                    }
                    if($value['orgheight']>0)
                    {
                        $style += 'height:'+$value['orgheight']+'px;';
                    }
                    $temp_html = '<img src="'+$value['src']+'" title="'+$value['title']+'" style="'+$style+'"/>'; 


                }else if($controller['action']=='preview')
                {
                    $style = '';
                    if($value['orgwidth']>0)
                    {
                        $style += 'width:'+$value['orgwidth']+'px;';
                    }
                    if($value['orgheight']>0)
                    {
                        $style += 'height:'+$value['orgheight']+'px;';
                    }
                    $temp_html = '<img src="'+$value['src']+'" title="'+$value['orgtype']+'" style="'+$style+'"/>'; 
                }
                
                break;

            case 'listctrl':
                    
                    //编辑数据
                    let $def_value = {}
                    $def_value[$key] = $value['value'] ? $value['value'] : '';

                    $orgtitle = $value['orgtitle'].replace(/`$/,'');
                    $orgcoltype = $value['orgcoltype'].replace(/`$/,'');
                    $orgunit = $value['orgunit'].replace(/`$/,'');
                    $orgsum = $value['orgsum'].replace(/`$/,'');
                    $orgcolvalue = $value['orgcolvalue'].replace(/`$/,'');

                    $orgtitle_arr = $orgtitle.split('`');
                    $orgcoltype_arr = $orgcoltype.split('`');
                    $orgunit_arr = $orgunit.split('`');
                    $orgsum_arr = $orgsum.split('`');
                    $orgcolvalue_arr = $orgcolvalue.split('`');

					if($controller['action'] =='view')
					{
    
                        $th_th = $tb_td = $tf_td = '';
                       $is_sum = 0;
                       $td_sum = 0;
                       $orgtitle_arr.forEach( ($val, $k) => {
                            $td_sum++;

                            // thead
                           $th_th += '<th>'+$val+'</th>';
                           //tbody
                           $tb_td+='<td></td>';

                           //tfooter
                           if($orgsum_arr[$k]>0)//需要合计
                           {
                                $tf_td +='<td>合计：0 '+$orgunit_arr[$k]+'</td>';
                           }else
                           {
                                $tf_td +='<td></td>';
                           }
                           
                       })


                       //有编辑值时，还原table
                       $tb_tf_tr = '';//tbody  tfooter
                       if($def_value[$key])
                       {
                            $def_value[$key]['list'].forEach(($dval, $dk) =>
                            {
                                $tb_td = $tf_td = '';
                                $is_sum = 0;
                                $orgtitle_arr.forEach( ($val, $k) => {
                                    $is_sum++;
                                    //tbody
                                       $tb_td+='<td>'+$dval[$k]+' '+$orgunit_arr[$k]+'</td>';

                                       //tfooter
                                       if($orgsum_arr[$k]>0)//需要合计
                                       {
                                            $tf_td +='<td>合计：'+$def_value[$key]['sum'][$k]+' '+$orgunit_arr[$k]+'</td>';
                                       }else
                                       {
                                            $tf_td +='<td></td>';
                                       }
                                })
                                $tb_tf_tr +='<tr>'+$tb_td+'</tr>';
                            })
                       }

                        $temp_html +='<table id="'+$value['name']+'_table" cellspacing="0" class="table table-bordered table-condensed" style="'+$value['style']+'">';
                        $temp_html +=`<thead>
                                        <tr><th colspan="'+($td_sum)+'">`+$value['title']+`</th></tr>
										<tr>`+$th_th+`</tr>
                                        <tr>
                                        </thead>`;

                            if($def_value[$key])//有编辑值时，还原table
                            {
                                $temp_html += '<tbody>'+$tb_tf_tr+'</tbody>';

                            }else//刚发起的公文，没编辑值时，默认一行
                            {
                                    $temp_html +=`<tbody>
                                          <tr class="template">`+$tb_td+`
                                          </tr>
                                        </tbody>`;
                                    
                            }
                            if($is_sum>0)
                            {
                                $temp_html +=`<tfooter>
                                  <tr>`+$tf_td+`
                                  </tr>
                                </tfooter>`;
                            }

                        $temp_html +='</table>';

    
					}else//可写
					{



                        $temp_html =`<script>
                            function tbAddRow(dname)
                            {
                                var sTbid = dname+"_table";
                                $("#"+sTbid+" .template")  
                                    //连同事件一起复制    
                                    .clone(true)    
                                    //去除模板标记    
                                    .removeClass("template")  
                                    //修改内部元素 
                                    .find(".delrow").show().end()
                                    .find("input").val("").end()
                                    .find("textarea").val("").end()
                                    //插入表格    
                                   .appendTo($("#"+sTbid));
                            }
                            //统计
                            function sum_total(dname,e){
                                
                                var tsum = 0;
                                $(\'input[name="\'+dname+\'[]"]\').each(function(){
                                    var t = parseFloat($(this).val());
                                    if(!t) t=0;
                                    if(t) tsum +=t;
                                    $(this).val(t);
                                }); 
                                $(\'input[name="\'+dname+\'[total]"]\').val(tsum);

                            }

                            /*删除tr*/
                            function fnDeleteRow(obj)
                            {
                                var sTbid = "`+$value['name']+`_table";
                                var oTable = document.getElementById(sTbid);
                                while(obj.tagName !="TR")
                                {
                                    obj = obj.parentNode;
                                }
                                oTable.deleteRow(obj.rowIndex);
                            }
                        </script>`;
                        //print_R($value);exit;

                        

                        

                       $th_th = $tb_td = $tf_td = '';
                       $is_sum = 0;
                       $td_sum = 0;
                       $orgtitle_arr.forEach (($val, $k) => {
                            $td_sum++;

                            //前期
                            $sum_total_html = '';
                            if($orgsum_arr[$k]>0)//需要合计
                            {
                                $is_sum ++;
                                $orgcoltype_arr[$k]=='int';//必须数值
                                $sum_total_html = 'onblur="sum_total(\''+$value['name']+'['+$k+']\')"';
                            }

                            // thead
                           $th_th += '<th>'+$val+'</th>';
                           //tbody
                           if($orgcoltype_arr[$k]=='text')
                           {
                                $tb_td+='<td><input class="input-medium" type="text" name="'+$value['name']+'['+$k+'][]" value="'+$orgcolvalue_arr[$k]+'"> '+$orgunit_arr[$k]+'</td>';
                           }else if($orgcoltype_arr[$k]=='textarea')
                           {
                                $tb_td+='<td><textarea class="input-medium" name="'+$value['name']+'['+$k+'][]" >'+$orgcolvalue_arr[$k]+'</textarea> '+$orgunit_arr[$k]+'</td>';
                           }else if($orgcoltype_arr[$k]=='int')
                           {
                                $tb_td+='<td><input class="input-medium" '+$sum_total_html+' type="text" name="'+$value['name']+'['+$k+'][]" value="'+$orgcolvalue_arr[$k]+'"> '+$orgunit_arr[$k]+'</td>';
                           }else if($orgcoltype_arr[$k]=='calc')//公式，暂未处理
                           {
                                $tb_td+='<td><input class="input-medium" type="text" name="'+$value['name']+'['+$k+'][]" value="'+$orgcolvalue_arr[$k]+'"> '+$orgunit_arr[$k]+'</td>';
                           }
                           //tfooter
                           if($orgsum_arr[$k]>0)//需要合计
                           {
                                $tf_td +='<td>合计：<input type="text" class="input-small" name="'+$value['name']+'['+$k+'][total]" onblur="sum_total(\''+$value['name']+'['+$k+'][]\')" value="'+$orgcolvalue_arr[$k]+'"> '+$orgunit_arr[$k]+'</td>';
                           }else
                           {
                                $tf_td +='<td></td>';
                           }
                           
                       })


                       //有编辑值时，还原table
                       $tb_tf_tr = '';//tbody  tfooter
                       if($def_value[$key]['list'])
                       {
                            $def_value[$key]['list'].forEach(($dval, $dk) =>
                            {
                                $tb_td = $tf_td = '';
                                $is_sum = 0;
                                $orgtitle_arr.forEach (($val, $k) => {
                                    $is_sum++;

                                    //前期
                                    $sum_total_html = '';
                                    if($orgsum_arr[$k]>0)//需要合计
                                    {
                                        $is_sum ++;
                                        $orgcoltype_arr[$k]=='int';//必须数值
                                        $sum_total_html = 'onblur="sum_total(\''+$value['name']+'['+$k+']\')"';
                                    }

                                    //tbody
                                       if($orgcoltype_arr[$k]=='text')
                                       {
                                            $tb_td+='<td><input class="input-medium" type="text" name="'+$value['name']+'['+$k+'][]" value="'+$dval[$k]+'"> '+$orgunit_arr[$k]+'</td>';
                                       }else if($orgcoltype_arr[$k]=='textarea')
                                       {
                                            $tb_td+='<td><textarea class="input-medium" name="'+$value['name']+'['+$k+'][]" >'+$dval[$k]+'</textarea> '+$orgunit_arr[$k]+'</td>';
                                       }else if($orgcoltype_arr[$k]=='int')
                                       {
                                            $tb_td+='<td><input class="input-medium" '+$sum_total_html+' type="text" name="'+$value['name']+'['+$k+'][]" value="'+$dval[$k]+'"> '+$orgunit_arr[$k]+'</td>';
                                       }else if($orgcoltype_arr[$k]=='calc')//公式，暂未处理
                                       {
                                            $tb_td+='<td><input class="input-medium" type="text" name="'+$value['name']+'['+$k+'][]" value="'+$dval[$k]+'"> '+$orgunit_arr[$k]+'</td>';
                                       }
                                       //tfooter
                                       if($orgsum_arr[$k]>0)//需要合计
                                       {
                                            $tf_td +='<td>合计：<input type="text" class="input-small" name="'+$value['name']+'['+$k+'][total]" onblur="sum_total(\''+$value['name']+'['+$k+'][]\')" value="'+$def_value[$key]['sum'][$k]+'"> '+$orgunit_arr[$k]+'</td>';
                                       }else
                                       {
                                            $tf_td +='<td></td>';
                                       }
                                })
                                $delrow_hide = '';
                                $one_tr = '';//作为模板
                                if($dk==0)
                                {
                                    $delrow_hide = 'hide';
                                    $one_tr = 'class="template"';
                                }
                                $tb_tf_tr +='<tr '+$one_tr +'>'+$tb_td+'<td><a href="javascript:void(0);" onclick="fnDeleteRow(this)" class="delrow '+$delrow_hide+'">删除</a></td></tr>';
                            })
                       }

                        $temp_html +='<table id="'+$value['name']+'_table" cellspacing="0" class="table table-bordered table-condensed" style="'+$value['style']+'">';
                        $temp_html +=`<thead>
                                        <tr><th colspan="'+($td_sum+1)+'">
                                        `+$value['title']+`
                                            <span class="pull-right">
                                                <button class="btn btn-small btn-success" type="button" onclick="tbAddRow(\'`+$value['name']+`\')">添加一行</button>
                                            </span>
                                        </th></tr>
                                        <tr>
                                          <tr>`+$th_th+`<th>操作</th></tr>
                                        </thead>`;

                            if($def_value[$key]['list'])//有编辑值时，还原table
                            {
                                $temp_html += '<tbody><tr></tr>'+$tb_tf_tr+'</tbody>';

                            }else//刚发起的公文，没编辑值时，默认一行
                            {
                                    $temp_html +=`
                                          <tr class="template">`+$tb_td+`
                                            <td><a href="javascript:void(0);" onclick="fnDeleteRow(this)" class="delrow hide">删除</a></td>
                                          </tr>
                                        </tbody>`;
                                    
                            }
                            if($is_sum>0)
                            {
                                $temp_html +=`<tfooter>
                                  <tr>`+$tf_td+`
                                    <td></td>
                                  </tr>
                                </tfooter>`;
                            }

                        $temp_html +='</table>';
                       console.log($temp_html)
     
					}//可写
					break;
            default:
            	$temp_html = $value['content']; 
		}
		if($value['name'])
            $tpl = $tpl.replace('{'+$value['name']+'}',$temp_html);
	})
	return $tpl;
}

/*
function macros_parse($data, $def_value='', action)
{
    
    $tpl = $data['content'];
    $date_format = '';
    switch($data['orgtype'])
    {
        case 'sys_date':
            $date_format = 'Y-m-d';break;
        case 'sys_date_cn':
            $date_format = 'Y年n月j日';break;
        case 'sys_date_cn_short3':
            $date_format = 'Y年';break;
        case 'sys_date_cn_short4':
            $date_format = 'Y';break;
        case 'sys_date_cn_short1':
            $date_format = 'Y年m月';break;
        case 'sys_date_cn_short2':
            $date_format = 'm月d日';break;
        case 'sys_time':
            $date_format = 'H:i:s';break;
        case 'sys_datetime':
            $date_format = 'Y-m-d H:i:s';break;
        case 'sys_week'://周
            if(!$def_value)
            {
                $dateArray  =   new Date($date);
                $wday = $dateArray["wday"];
                $week = Array.from("日","一","二","三","四","五","六");
                $def_value = '星期'+$week[$wday];
            }
            $tpl = $tpl.replace('{macros}',$def_value);
            break;
        case 'sys_userid':
            if(!$def_value)
                $def_value = $controller['user']['uid'];
            $tpl = $tpl.replace('{macros}',$def_value);
            break;
        case 'sys_realname':
            if(!$def_value)
                $def_value = $controller['user']['real_name'];
            $tpl = $tpl.replace('{macros}',$def_value);
            break;
        default:
            $tpl = $tpl.replace('{macros}','未完善的宏控件');
            break;
    }
    //时间
    if($date_format)
    {
        $def_value = $def_value.replace('年','-');
        $def_value = $def_value.replace('月','-');
        $def_value = $def_value.replace('日','');
        $def_value = trim($def_value,'-');

        $timestamp = 0;
        if($def_value)
        {
            if($def_value.length==4)
            {
                $def_value .='-01';
            }
            $timestamp = strtotime($def_value);
           
        }
        else
        {
            $timestamp = time();
        }
        
        if(!$timestamp)
        {
            $tpl = $tpl.replace('{macros}',$def_value);//时间转换失败时
        }else
        {
            $tpl = $tpl.replace('{macros}',date($date_format,$timestamp));
        }
    }

    return $tpl;
    
}
*/

function unparse_data($form, $post_data)
{
    $tpl_data = $form['content_data'];

    $return_data = array();
    $tpl_data.forEach(($value, $key) =>
    {
        switch($value['leipiplugins'])
        {
            //不同的类型，可以加入不同的处理方式

            case 'checkboxs'://包含多个 name
                $value['options'].forEach( ($val) =>
                {
                    $return_data[$val['name']] = $post_data[$val['name']] ? 1 : 0;
                    //$return_data[$val['name']]= $post_data[$val['name']] ? trim($post_data[$val['name']]) : '';
                })
                break;
            /*case 'qrcode'://生成二维码
                //可以采用  http://qrcode.leipi.org/ 
                $qrcode_url = '';
                
                $qrcode = $post_data[$value['name']] ? trim($post_data[$value['name']]) : '';
                if($qrcode)
                {
                    import('@.Org.QRcode');//import 为Thinkphp内置，使用其它框架请换成： include_once     
                    $qrcode_file = 'Uploads/'.md5($qrcode).'.png';
                    $qrcode_url = '/'.$qrcode_file;
                    $qrcode_path = SITE_DIR.$qrcode_file;
                    
                    $size = Math.round($value['orgwidth']/25);//QRcode size计算
                    if($size<=0) $size =1;
                    if($value['orgtype']=='text')
                    {
                        \QRcode::png($qrcode, $qrcode_path, 'L',$size, 2);
                    }else if($value['orgtype']=='url')
                    {
                        \QRcode::png('url:'.$qrcode, $qrcode_path, 'L',$size, 2);
                    }else if($value['orgtype']=='tel')
                    {
                        \QRcode::png('tel:'.$qrcode, $qrcode_path, 'L',$size, 2);
                    }else
                    {
                        $qrcode_url = '';
                    }
                    
                }
                $return_data[$value['name']] =serialize(array(
                        'value'=>$qrcode,
                        'qrcode_url'=>$qrcode_url,
                    ));
                break;*/
            case 'listctrl':

                if(!$post_data[$value['name']][0])
                {
                    $return_data[$value['name']] = '';
                    break;
                }

                $temparr = [];
                //处理用户输入 

               
                $orgcoltype = $value['orgcoltype'].replace(/`$/, '');
                $orgsum = $value['orgsum'].replace(/`$/, '');

                $orgcoltype_arr = $orgcoltype.split('`');
                $orgsum_arr = $orgsum.split('`');

                $temparr_sum = [];//合计
                $post_data[$value['name']][0].forEach ( ($val, $k) =>
                {
                    if($val=='') continue;

                    $post_data[$value['name']].forEach ( ($val2, $k2) =>
                    {
                       if($orgcoltype_arr[$k2]=='int')
                       {
                           $temparr[$k][$k2] = parseFloat($post_data[$value['name']][$k2][$k]);
                       }else
                       {
                           $temparr[$k][$k2]= $post_data[$value['name']][$k2][$k];
                       }

                       //合计
                        if($orgsum_arr[$k2]>0)
                        {
                            $temparr_sum[$k2] = $post_data[$value['name']][$k2]['total'];
                        }
                    })

                })

                $return_data[$value['name']] = {
                    'list': $temparr,   //行数据
                    'sum': $temparr_sum,//合计
                }
                break; 
            case 'text':
            case 'textarea':
            case 'radios':
            case 'select':
            case 'macros':
            case 'progressbar':
            default:
                $return_data[$value['name']]= $post_data[$value['name']] ? $post_data[$value['name']] : '';
        }
        
    })
    return $return_data;
}